package cn.the.angry.physics;

import org.jbox2d.collision.shapes.PolygonDef;
import org.jbox2d.dynamics.World;

import cn.the.angry.model.Actor;

public class AngryRectangle extends AngryShape {
	private PolygonDef rectDef;
	

	public AngryRectangle(World world, float _x, float _y, float _density, float _friction
			, float _restitution, float _width, float _height, float angle, final Actor actor) {
		super();
		setRectDef(new PolygonDef());
		getRectDef().density = _density;
		getRectDef().friction = _friction;
		getRectDef().restitution = _restitution;
		getRectDef().setAsBox(_width/2, _height/2);
		
		bodyDef.angle=angle;
		bodyDef.position.x = _x+_width/2;
		bodyDef.position.y = _y+_height/2;
		body = world.createBody(bodyDef);
		body.createShape(getRectDef());
		body.setUserData(actor);
		if(_density != 0){
			body.setMassFromShapes();
		}
		
	}

	public void setRectDef(PolygonDef rectDef) {
		this.rectDef = rectDef;
	}

	public PolygonDef getRectDef() {
		return rectDef;
	}

}
